package com.example.basic.web.controller.stretcher;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.stretcher.Stretcher;
import com.example.basic.web.service.stretcher.StretcherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(value  = "担架板", tags = {"担架板"})
@RestController
@RequestMapping("/api/v1/byg/stretcher")
public class StretcherController {

    @Resource
    private StretcherService stretcherService;

    @Log(title = "担架板", description = "新增")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    public Result<Boolean> add(
            @ApiParam(name = "layerNum", value = "层数") @RequestParam(required = false) Integer layerNum,
            @ApiParam(name = "columnNum", value = "列数") @RequestParam(required = false) Integer columnNum) {
        return ResultGenerator.genSuccessResult(stretcherService.add(layerNum,columnNum));
    }


    @Log(title = "担架板", description = "列表")
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/queryList")
    public Result<IPage<Stretcher>> queryList(
            @ApiParam(name = "isUse", value = "0-未使用,1-使用") @RequestParam(required = false) String isUse,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<Stretcher> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(stretcherService.queryList(queryPage,isUse));
    }

    @Log(title = "担架板", description = "修改")
    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/modify")
    public Result<Boolean> modify(
            @ApiParam(name = "id", value = "唯一id") @RequestParam(required = true) String id,
            @ApiParam(name = "point", value = "点位") @RequestParam(required = true) String point) {
        return ResultGenerator.genSuccessResult(stretcherService.modify(id,point));
    }
}
